package db.entities;

import db.entities.embeddables.Address;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;

/**
 *
 * @author jeroen
 */
@NamedQueries(
{
    @NamedQuery (
        name="findPatientByUsername",
        query="SELECT pa FROM Patient pa WHERE pa.username = :username"
    )
})
@Entity
public class Patient implements Serializable {
    /**********
     * FIELDS *
     **********/

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(unique=true, nullable = false)
    private String username;

    @Column(nullable = false)
    private String password;

    @Column(nullable = false)
    private String ssn; //social security number

    private String name;

    private String surname;

    private String bloodgroup;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Calendar birthday;

    private Address address;

    private ArrayList<String> GPs = new ArrayList<String>();;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date lastConsult;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date nextConsult;


    /**************
     * CONSTRUCTORS
     **************/

    public Patient(){

    }

    public Patient(String username, String password, String ssn){
        this.username = username;
        this.password = password;
        this.ssn = ssn;
    }

    public Patient(String username, String password, String ssn, String name,
                 String surname, String bloodgroup, Calendar birthday){
        this.username = username;
        this.password = password;
        this.ssn = ssn;
        this.name = name;
        this.surname = surname;
        this.bloodgroup = bloodgroup;
        this.birthday = birthday;
    }



    /***********
     * METHODS *
     ***********/


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(String a1, String a2, String city, String postalCode, String country, String phone, String email) {
        this.address = new Address(a1, a2, city, postalCode, country, phone, email);
    }

    public Calendar getBirthday() {
        return birthday;
    }

    public void setBirthday(Calendar birthday) {
        this.birthday = birthday;
    }

    public String getBloodgroup() {
        return bloodgroup;
    }

    public void setBloodgroup(String bloodgroup) {
        this.bloodgroup = bloodgroup;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSsn() {
        return ssn;
    }

    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public List<String> getGPs() {
        return GPs;
    }

    public void setGPs(ArrayList<String> GPs) {
        this.GPs = GPs;
    }

    public void addGP(String GP){
        GPs.add(GP);
    }

    public void removeGP(String GP){
        GPs.remove(GP);
    }

    public Date getLastConsult() {
        return lastConsult;
    }

    public void setLastConsult(Date lastConsult) {
        this.lastConsult = lastConsult;
    }

    public Date getNextConsult() {
        return nextConsult;
    }

    public void setNextConsult(Date nextConsult) {
        this.nextConsult = nextConsult;
    }



    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Patient)) {
            return false;
        }
        Patient other = (Patient) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "db.Patient[id=" + id + "]";
    }


}
